package com.design.designmode.action.observe;

/**
 * @author hxl
 * @since 2023-04-18
 */
public class ConcreteObserver implements Observer {
    private String name;
    private String state;

    private Subject subject;

    public ConcreteObserver(String name, Subject subject) {
        this.name = name;

        this.subject = subject;
        subject.attach(this);

        state = subject.getState();
    }


    @Override
    public void update() {
        System.out.println(name + "收到通知");
        state = subject.getState(); // 让当前观察者的状态 和 改变了状态之后的目标的状态保持一致
        System.out.println(name + "改变后的状态为：" + state);
    }
}
